#include "FrameRate.h"
using namespace std;


FrameRate::FrameRate() {
	textColour = {120,255,0};
	
	TTF_Init();

	ttf = TTF_OpenFont("Fonts/primaryFont.ttf",14);
}

void FrameRate::applyFrames(int ticks,int start_of_current_frame, int start_of_previous_frame, SDL_Surface* baseSurface){
	if(ticks> 1000) {
	int frameRates = 1000/ (start_of_current_frame - start_of_previous_frame);
	string showFrames = "Frames : " + convertInt(frameRates);
	string timer = "Time : " + convertInt(ticks);
	frameRateTtf = TTF_RenderText_Solid(ttf, showFrames.c_str(), textColour);
	timerTtf =  TTF_RenderText_Solid(ttf, timer.c_str(), textColour);
	
	ScreenHelper::apply_surface(10,80, frameRateTtf, baseSurface );
	ScreenHelper::apply_surface(10,50, timerTtf, baseSurface );
	}
}

void FrameRate::closeFont() {
	TTF_CloseFont( ttf );
	TTF_Quit();
}

string FrameRate:: convertInt(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}